package main

import "C"
import (
	"d4gohttp/http"
	"fmt"
	"github.com/gogf/gf/encoding/gbase64"
)

func main() {

}

//export ZhResStr
func ZhResStr(str *C.char) *C.char{
	// base64解码
	v,e:=gbase64.DecodeString(C.GoString(str))
	if e != nil {
		panic(e.Error())
	} else {
		fmt.Println("传入的中文字符串是:",string(v))
	}
	// base64编码
	cs := C.CString(gbase64.EncodeString(v))
	return cs
}

//export MyTest
func MyTest(str *C.char) {
	fmt.Println(str)
	s1 := C.GoString(str)
	fmt.Println(s1)
}

//export Get
func Get(url, parameter *C.char) *C.char {
	var (
		gUrl,gParameter []byte
		res string
		cRes *C.char
	)
	gUrl,_=gbase64.DecodeString(C.GoString(url))
	gParameter, _ = gbase64.DecodeString(C.GoString(parameter))
	v, e := http.HttpGet(string(gUrl), string(gParameter))
	if e != nil {
		res = e.Error()
	} else {
		res = v
	}
	cRes = C.CString(gbase64.EncodeString([]byte(res)))
	return cRes
}

//export Post
func Post(url, parameter *C.char) *C.char {
	var (
		gUrl,gParameter []byte
		res string
		cRes *C.char
	)
	gUrl,_=gbase64.DecodeString(C.GoString(url))
	gParameter, _ = gbase64.DecodeString(C.GoString(parameter))
	v, e := http.HttpPost(string(gUrl), string(gParameter))
	if e != nil {
		res = e.Error()
	} else {
		res = v
	}
	cRes = C.CString(gbase64.EncodeString([]byte(res)))
	return cRes
}


